﻿#pragma once


// CNodeDlg 对话框
// 不继承CDialogEx MFC中窗体中使用CFileDialog导致菜单栏变灰
class CNodeDlg : public CDialog
{
	enum EType {
		ANSI = 0,
		UTF16_LE,
		UTF16_BE,
		UTF8,
		UTF8BOM
	};
	EType n_type = UTF8;
	DECLARE_DYNAMIC(CNodeDlg)
	TCHAR* szFilter = _T("文本文件 (*.txt)|*.txt|配置文件 (*.ini;*.inf)|*.ini;*.inf|All Files (*.*)|*.*||");

public:
	CNodeDlg(CWnd* pParent = nullptr);   // 标准构造函数
	virtual ~CNodeDlg();

// 对话框数据
#ifdef AFX_DESIGN_TIME
	enum { IDD = IDD_NODE };
#endif

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持

	DECLARE_MESSAGE_MAP()
public:
	afx_msg void OnSize(UINT nType, int cx, int cy);
	virtual BOOL OnInitDialog();
	void LoadFont();
	virtual void OnOK();
	virtual void OnCancel();
	virtual void PostNcDestroy();
	afx_msg void OnDestroy();
	afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
	afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
	afx_msg void OnClose();
	afx_msg void OnFileNew();
	afx_msg void OnFileNewDlg();
	afx_msg void OnFileSaveAs();
	afx_msg void OnFileOpen();
	afx_msg void OnFileSave();
	afx_msg void OnFileSet();
	afx_msg void OnFilePrint();
	afx_msg void OnFileExit();
	afx_msg void OnEditUndo();
	afx_msg void OnEditCut();
	afx_msg void OnEditCopy();
	afx_msg void OnEditPaste();
	afx_msg void OnEditDel();
	afx_msg void OnEditSelectAll();
	afx_msg void OnEditGoto();
	CEdit m_edit;
protected:
	afx_msg LRESULT OnUmNotify(WPARAM wParam, LPARAM lParam);
public:
	BOOL Prompt();
	CString m_sFile;
	HACCEL m_hAccel;
	CFont m_font;
	COLORREF m_clText{0x000000}, m_clBlack{ 0xffffff };
	CBrush m_brush;
	CFindReplaceDialog* m_pReplaceDlg;
	void UpdateTitle();
	BOOL SelectFile();
	afx_msg void OnDropFiles(HDROP hDropInfo);
	void ReadText(LPCTSTR sFile);
	void ParseText(LPSTR p);
	CString GetSelText();
	afx_msg void OnEditSearch();
	afx_msg void OnEditFind();
	afx_msg void OnEditNext();
	afx_msg void OnEditPrev();
	afx_msg void OnEditReplace();
	afx_msg void OnEditDate();
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	afx_msg void OnFormatFont();
	afx_msg void OnFormatText();
	afx_msg void OnFormatBack();
	
	afx_msg LRESULT OnFindReplace(WPARAM wParam, LPARAM lParam);
	void SearchDown();
	void SearchUp();
	void ReplaceAll();
	void ReplaceCurrent();
	afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
	afx_msg void OnFormatWrap();
};
